/** 
 * \defgroup Control The Control
 *
 * \details
 * Control algorithm using PID controller to stabilize the system.
 * Fixed-point calculation used for PID control calculation.
 */

#ifndef __PIDFXP_H__
#define __PIDFXP_H__

/** \struct PIDFXP
 *  \brief Data for PID controller.
 *  \ingroup Control
 */
typedef struct
{
    L1_INT32 PQ16; ///< Proportional coefficient
    L1_INT32 IQ16; ///< Integration coefficient
    L1_INT32 DQ16; ///< Derivative coefficient
    L1_INT32 WQ16; ///< Windup coefficient
    L1_INT32 LQ8;  ///< Limit coefficient

    L1_INT32 windupQ24; ///< Windup variable
    L1_INT32 int_z;     ///< Integrator state
    L1_INT32 der_z;     ///< Derivative state
}   PIDFXP;

/** \brief Initialise internal memory of the PID controller.
 *  \ingroup Control
 */
void pidInitFXP(PIDFXP* pid, L1_INT32 P0, L1_INT32 I0, L1_INT32 D0, L1_INT32 W0, L1_INT32 L0);

/** \brief Execute the PID controller.
 *  \ingroup Control
 */
L1_INT32 pidRunFXP(L1_INT32 inputQ24, L1_INT32 sensorQ24, PIDFXP* pid);

#endif // __PIDFXP_H__
